/*
 * Copyright (c) 2010 Andy Aspell-Clark
 * 
 * Permission is hereby granted, free of charge, to any person
 * obtaining a copy of this software and associated documentation
 * files (the "Software"), to deal in the Software without
 * restriction, including without limitation the rights to use,
 * copy, modify, merge, publish, distribute, sublicense, and/or sell
 * copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following
 * conditions:
 * 
 * The above copyright notice and this permission notice shall be
 * included in all copies or substantial portions of the Software.
 * 
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */
package uk.org.aspellclark.agenedb.view;

import uk.org.aspellclark.agenedb.R;
import uk.org.aspellclark.agenedb.db.DatabaseObjectContainer;
import uk.org.aspellclark.agenedb.gedcom.Gedcom;
import uk.org.aspellclark.agenedb.gedcom.model.Header;
import android.app.Activity;
import android.os.Bundle;
import android.widget.TextView;

public class GedcomFileInformationView extends Activity {

	static class GedcomFileInformationViewHolder {
		static TextView sourSysId;
		static TextView sourName;
		static TextView sourCorpName;
		static TextView sourCorpAddr;
		static TextView sourData;
		static TextView sourDataDate;
		static TextView sourDataCopyright;
		static TextView sourDestName;
		static TextView sourDateTime;
		static TextView sourSubm;
		static TextView sourSubn;
		static TextView sourFile;
		static TextView sourCopyright;
		static TextView sourGedcVers;
		static TextView sourGedcForm;
		static TextView sourChar;
		static TextView sourCharVers;
		static TextView sourLang;
		static TextView sourPlac;
		static TextView sourPlacForm;
		static TextView sourNote;

		static TextView nbrIndividualsVw;
		static TextView nbrFamiliesVw;
	}

	/** Called when the activity is first created. */
	@Override
	public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);

		this.setContentView(R.layout.gedcom_file_details);
		this.updateDetails();
	}

	private void updateDetails() {
		if (Gedcom.getInstance() != null) {
			//Header hdrRcrd = Gedcom.getInstance().header;
			Header hdrRcrd = DatabaseObjectContainer.headerCntrlr.getHeader();
			if (hdrRcrd != null) {
				try {
					GedcomFileInformationViewHolder.sourSysId = (TextView) this
							.findViewById(R.id.gedcomFileInfoSourceSystemId);
					GedcomFileInformationViewHolder.sourSysId.setText("Source System Id: " + hdrRcrd.sourceSystem.systemId);

					GedcomFileInformationViewHolder.sourName = (TextView) this
							.findViewById(R.id.gedcomFileInfoSourceNameOfProd);
					GedcomFileInformationViewHolder.sourName.setText("Source System Name: "
							+ hdrRcrd.sourceSystem.productName);

					GedcomFileInformationViewHolder.sourCorpName = (TextView) this
							.findViewById(R.id.gedcomFileInfoSourceCorpName);
					GedcomFileInformationViewHolder.sourCorpName
							.setText("Corporation name: "
									+ (hdrRcrd.sourceSystem.corporation.businessName != null ? hdrRcrd.sourceSystem.corporation.businessName
											: ""));

					GedcomFileInformationViewHolder.sourCorpAddr = (TextView) this
							.findViewById(R.id.gedcomFileInfoSourceCorpAddress);
					GedcomFileInformationViewHolder.sourCorpAddr
							.setText("Corporation address: "
									+ (hdrRcrd.sourceSystem.corporation.address != null ? hdrRcrd.sourceSystem.corporation.address
											: ""));

					GedcomFileInformationViewHolder.sourData = (TextView) this.findViewById(R.id.gedcomFileInfoSourceData);
					GedcomFileInformationViewHolder.sourData.setText("Name of Data: "
							+ (hdrRcrd.sourceSystem.sourceData.name != null ? hdrRcrd.sourceSystem.sourceData.name : ""));

					GedcomFileInformationViewHolder.sourDataDate = (TextView) this
							.findViewById(R.id.gedcomFileInfoSourceDataDate);
					GedcomFileInformationViewHolder.sourDataDate.setText("Publication Date: "
							+ (hdrRcrd.sourceSystem.sourceData.publishDate != null ? hdrRcrd.sourceSystem.sourceData.publishDate
									: ""));

					GedcomFileInformationViewHolder.sourDataCopyright = (TextView) this
							.findViewById(R.id.gedcomFileInfoSourceDataCopr);
					GedcomFileInformationViewHolder.sourDataCopyright.setText("Copyright: "
							+ (hdrRcrd.sourceSystem.sourceData.copyright != null ? hdrRcrd.sourceSystem.sourceData.copyright
									: ""));

					GedcomFileInformationViewHolder.sourDestName = (TextView) this
							.findViewById(R.id.gedcomFileInfoSourceDataDate);
					GedcomFileInformationViewHolder.sourDestName.setText("Destinaton system: "
							+ (hdrRcrd.destinationSystem != null ? hdrRcrd.destinationSystem : ""));

					GedcomFileInformationViewHolder.sourDateTime = (TextView) this.findViewById(R.id.gedcomFileInfoDateTime);
					GedcomFileInformationViewHolder.sourDataDate.setText("Transmission date: "
							+ (hdrRcrd.date != null ? hdrRcrd.date : ""));

					GedcomFileInformationViewHolder.sourSubm = (TextView) this.findViewById(R.id.gedcomFileInfoSubm);
					GedcomFileInformationViewHolder.sourSubm.setText("Submission: "
							+ (hdrRcrd.submission != null ? hdrRcrd.submission : ""));

					GedcomFileInformationViewHolder.sourSubn = (TextView) this.findViewById(R.id.gedcomFileInfoSubn);
					GedcomFileInformationViewHolder.sourSubn.setText("Submitter: "
							+ (hdrRcrd.submitter != null ? hdrRcrd.submitter : ""));

					GedcomFileInformationViewHolder.sourFile = (TextView) this.findViewById(R.id.gedcomFileInfoFile);
					GedcomFileInformationViewHolder.sourFile.setText("Filename: "
							+ (hdrRcrd.fileName != null ? hdrRcrd.fileName : ""));

					GedcomFileInformationViewHolder.sourCopyright = (TextView) this
							.findViewById(R.id.gedcomFileInfoCopyright);
					GedcomFileInformationViewHolder.sourCopyright.setText("Copyright: "
							+ (hdrRcrd.copyrightData != null ? hdrRcrd.copyrightData : ""));

					GedcomFileInformationViewHolder.sourGedcVers = (TextView) this
							.findViewById(R.id.gedcomFileInfoGedCVersion);
					GedcomFileInformationViewHolder.sourGedcVers.setText("Gedcom Version: "
							+ (hdrRcrd.gedcomVersion.versionNumber != null ? hdrRcrd.gedcomVersion.versionNumber : ""));

					GedcomFileInformationViewHolder.sourGedcForm = (TextView) this.findViewById(R.id.gedcomFileInfoGedCForm);
					GedcomFileInformationViewHolder.sourGedcForm.setText("Gedcom Form: "
							+ (hdrRcrd.gedcomVersion.gedcomForm != null ? hdrRcrd.gedcomVersion.gedcomForm : ""));

					GedcomFileInformationViewHolder.sourChar = (TextView) this.findViewById(R.id.gedcomFileInfoCharSet);
					GedcomFileInformationViewHolder.sourChar.setText("Character set: "
							+ (hdrRcrd.characterSet.characterSetName != null ? hdrRcrd.characterSet.characterSetName : ""));

					GedcomFileInformationViewHolder.sourCharVers = (TextView) this.findViewById(R.id.gedcomFileInfoCharVers);
					GedcomFileInformationViewHolder.sourCharVers.setText("Char set version: "
							+ (hdrRcrd.characterSet.versionNum != null ? hdrRcrd.characterSet.versionNum : ""));

					GedcomFileInformationViewHolder.sourLang = (TextView) this.findViewById(R.id.gedcomFileInfoLang);
					GedcomFileInformationViewHolder.sourLang.setText("Language: "
							+ (hdrRcrd.language != null ? hdrRcrd.language : ""));

					GedcomFileInformationViewHolder.sourPlac = (TextView) this.findViewById(R.id.gedcomFileInfoPlac);
					GedcomFileInformationViewHolder.sourPlac.setText("Place: "
							+ (hdrRcrd.placeStructure != null ? hdrRcrd.placeStructure : ""));

					GedcomFileInformationViewHolder.sourNote = (TextView) this.findViewById(R.id.gedcomFileInfoNotes);
					StringBuffer note = new StringBuffer();
					for (String str : hdrRcrd.notes) {
						note.append(str);
					}
					GedcomFileInformationViewHolder.sourNote.setText("Filename: " + note.toString());

					GedcomFileInformationViewHolder.nbrIndividualsVw = (TextView) this
							.findViewById(R.id.gedcomFileInfoNbrRecordsIndividual);
					GedcomFileInformationViewHolder.nbrIndividualsVw.setText("X Individuals");

					GedcomFileInformationViewHolder.nbrFamiliesVw = (TextView) this
							.findViewById(R.id.gedcomFileInfoNbrRecordsFamily);
					GedcomFileInformationViewHolder.nbrFamiliesVw.setText("X Families");
				} catch (Exception e) {
					String errMsg = e.getMessage();
				}
			}
		}
	}
}